package com.example.arithmeticleetcode.learnArithmetic;

import com.example.arithmeticleetcode.util.TimeTool;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.List;

/**
 * @program: arithmetic-leetcode
 * @description:
 * @author: FangZhen
 * @create: 2020-06-23 19:37
 **/
public class Demo1 {

    public static void main(String[] args) {
        int n = 46;

        TimeTool.check("fib1", new TimeTool.Task() {
            @Override
            public void execute() {
                System.out.println(fib1(n));
            }
        });

        TimeTool.check("fib2", new TimeTool.Task() {
            @Override
            public void execute() {
                System.out.println(fib2(n));
            }
        });

    }

    /**
     * 菲波那切数
     *
     * @param n
     * @return
     */
    public static int fib1(int n) {
        if (n <= 1) return n;
        return fib1(n - 1) + fib1(n - 2);
    }

    /**
     * 菲波那切数
     *
     * @param n
     * @return
     */
    public static int fib2(int n) {
        if (n <= 1) return n;
        int first = 0;
        int second = 1;
        for (int i = 0; i < n - 1; i++) {
            int sum = first + second;
            first = second;
            second = sum;
        }
        return second;
    }

    public static Object getObejct() {
        List<B> list = new ArrayList<>();
        list.add(new B("name0", 20));
        list.add(new B("name1", 21));
        list.add(new B("name2", 22));
        return list;
    }
}

@Data
@AllArgsConstructor
@NoArgsConstructor
class B {
    private String name;

    private Integer age;
}